package com.lecyon.farm.vo.view;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.base.Objects;
import com.lecyon.farm.common.constant.CommonConstant;
import com.lecyon.farm.common.constant.FarmSysConstant;
import com.lecyon.farm.util.StringHelper;
import com.lecyon.farm.vo.base.BaseViewVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.time.LocalDate;

/**
 * @author YaoZheng
 * @since 2020-04-02
 */
@Data
@ApiModel("农机作业历史")
public class FmWorkVo extends BaseViewVo {

    @ApiModelProperty(name = "id", value = "编号")
    private String id;

    @ApiModelProperty(name = "carId", value = "农机号")
    private String carId;

    @ApiModelProperty(name = "carOwner", value = "车主")
    private String carOwner;

    @ApiModelProperty(name = "carOwnerPhone", value = "电话")
    private String carOwnerPhone;

    @ApiModelProperty(name = "type", value = "耕种类型")
    private String type;

    @ApiModelProperty(name = "type_dict", value = "耕种类型Dict")
    private String typeDict;

    @ApiModelProperty(name = "workDate", value = "作业日期")
    @JsonFormat(pattern = CommonConstant.DATE_FORMAT_PATTERN)
    private LocalDate workDate;

    @ApiModelProperty(name = "depth", value = "深度")
    private String depth;

    @ApiModelProperty(name = "passRate", value = "合格率")
    private String passRate;

    @ApiModelProperty(name = "workLandarea", value = "作业面积")
    private String workLandarea;

    @ApiModelProperty(name = "submitLandarea", value = "提交面积")
    private String submitLandarea;

    @ApiModelProperty(name = "qualifiedLandarea", value = "合格面积")
    private String qualifiedLandarea;

    @ApiModelProperty(name = "repeatArea", value = "重复面积")
    private Double repeatArea;

    @ApiModelProperty(name = "distance", value = "里程")
    private String distance;

    @ApiModelProperty(name = "overlapRate", value = "重叠率")
    private String overlapRate;

    @ApiModelProperty(name = "repeatRate", value = "重耕率")
    private String repeatRate;

    @ApiModelProperty(name = "missRate", value = "漏耕率")
    private String missRate;

    @ApiModelProperty(name = "userCode", value = "用户编号")
    private String userCode;

    private String count;

    @ApiModelProperty(name = "todayFlow", value = "今日预估流量")
    private String todayFlow;

    @ApiModelProperty(name = "todayArea", value = "今日预估产量")
    private String todayArea;

    @ApiModelProperty(name = "todayDepth", value = "今日平均深度")
    private String todayDepth;

    @ApiModelProperty(name = "typeCode", value = "类型代码")
    private String typeCode;

    @ApiModelProperty(name = "beginDate", value = "开始日期")
    private LocalDate beginDate;

    @ApiModelProperty(name = "endDate", value = "结束日期")
    private LocalDate endDate;

    @ApiModelProperty(name = "cooperationId", value = "合作社编号")
    private String cooperationId;

    @ApiModelProperty(name = "cooperationName", value = "合作社名称")
    private String cooperationName;

    @ApiModelProperty(name = "totalFlow", value = "植保流量")
    private String totalFlow;

    @ApiModelProperty(name = "identify", value = "新旧平台标识")
    private String identify;

    @ApiModelProperty(name = "seed", value = "播种数")
    private String seed;

    @ApiModelProperty(name = "seed_per_mu", value = "播种数/亩")
    private String seedPerMu;

    @ApiModelProperty(name = "isNewRecord", value = "是否为新平台记录")
    private boolean newRecord;

    @ApiModelProperty(name = "fmCarVo", value = "农机基本信息")
    private FmCarVo fmCarVo;

    public boolean isNewRecord() {
        if (CommonConstant.WHETHER_TRUE.equals(identify)) {
            newRecord = true;
        }
        return newRecord;
    }

    public String getTypeDict() {
        if (StringHelper.isNotEmpty(type)) {
            boolean flag = FarmSysConstant.SYS_JOB_TYPE_MAP.containsKey(type);
            if (flag) {
                typeDict = FarmSysConstant.SYS_JOB_TYPE_MAP.get(type);
                if (StringHelper.isNotEmpty(typeDict)) {
                    return typeDict;
                }
            }
        }
        return typeDict;
    }

    public Double getRepeatArea() {
        if (StringHelper.isNotEmpty(workLandarea) && StringHelper.isNotEmpty(repeatRate)) {
            Double workArea = Double.parseDouble(workLandarea);
            Double repeatRateDouble = Double.parseDouble(repeatRate);
            return workArea * repeatRateDouble;
        }
        return repeatArea;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        FmWorkVo fmWorkVo = (FmWorkVo) o;
        return Objects.equal(carId, fmWorkVo.carId) &&
                Objects.equal(carOwner, fmWorkVo.carOwner) &&
                Objects.equal(carOwnerPhone, fmWorkVo.carOwnerPhone) &&
                Objects.equal(type, fmWorkVo.type) &&
                Objects.equal(workDate, fmWorkVo.workDate) &&
                Objects.equal(depth, fmWorkVo.depth) &&
                Objects.equal(passRate, fmWorkVo.passRate) &&
                Objects.equal(workLandarea, fmWorkVo.workLandarea) &&
                Objects.equal(submitLandarea, fmWorkVo.submitLandarea) &&
                Objects.equal(qualifiedLandarea, fmWorkVo.qualifiedLandarea) &&
                Objects.equal(distance, fmWorkVo.distance) &&
                Objects.equal(overlapRate, fmWorkVo.overlapRate) &&
                Objects.equal(repeatRate, fmWorkVo.repeatRate) &&
                Objects.equal(missRate, fmWorkVo.missRate) &&
                Objects.equal(userCode, fmWorkVo.userCode) &&
                Objects.equal(count, fmWorkVo.count) &&
                Objects.equal(todayFlow, fmWorkVo.todayFlow) &&
                Objects.equal(todayArea, fmWorkVo.todayArea) &&
                Objects.equal(todayDepth, fmWorkVo.todayDepth) &&
                Objects.equal(typeCode, fmWorkVo.typeCode) &&
                Objects.equal(beginDate, fmWorkVo.beginDate) &&
                Objects.equal(endDate, fmWorkVo.endDate) &&
                Objects.equal(cooperationId, fmWorkVo.cooperationId) &&
                Objects.equal(cooperationName, fmWorkVo.cooperationName) &&
                Objects.equal(totalFlow, fmWorkVo.totalFlow) &&
                Objects.equal(identify, fmWorkVo.identify) &&
                Objects.equal(seed, fmWorkVo.seed);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(super.hashCode(), carId, carOwner, carOwnerPhone, type, workDate, depth, passRate, workLandarea, submitLandarea, qualifiedLandarea, distance, overlapRate, repeatRate, missRate, userCode, count, todayFlow, todayArea, todayDepth, typeCode, beginDate, endDate, cooperationId, cooperationName, totalFlow, identify, seed);
    }
}
